<template>
    <rx-layout>
        <div slot="left" width="220" showButton="true">
            <rx-fit>
                <rx-category-treeeditor
                    cat-key="FORM"
                    :statisticConfig="statisticConfig"
                    :edit="true"
                    @handSelect="handSelect"
                    :async="true"
                    v-if="isShowManageTree"
                    :isAdmin="isManageToTree"
                    :checkToDel="true"
                ></rx-category-treeeditor>
            </rx-fit>
        </div>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="formLiteComponentAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="add">{{ $ti18('rxList.newBtn', '新建') }}
                        </rx-button>
                        <a-button v-if="selectedRowKeys.length > 0"
                                  type="primary"
                                  icon="switcher" @click="openCategoryDialog">
                            {{$ti18('rxList.changeCategory','切换分类')}}
                        </a-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0"
                                             alias="formLiteComponentEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="formLiteComponentDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('componentName','组件名称')">
                            <a-input :placeholder="i18n('componentName','请输入组件名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('componentAlias','组件别名')">
                            <a-input :placeholder="i18n('componentAlias','请输入组件别名','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formLiteComponent/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="enabled" slot-scope="{text,record, index}">
                       <a-tag :color="statusMap[text].color">
                           <span>{{ statusMap[text].text }}</span>
                       </a-tag>
                    </span>
                    <span slot="nodeType" slot-scope="{text,record, index}">
                        <span>{{ nodeTypeMap[text]}}</span>
                    </span>
                    <span slot="type" slot-scope="{text,record, index}">
                        <span>{{ typeMap[text]}}</span>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormLiteComponentApi from '@/api/form/core/formLiteComponent'
import FormLiteComponentEdit from './FormLiteComponentEdit'
import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
import RxCategoryTreeeditor from "@/components/redxun/rx-category-treeeditor";
import ChangeCategory from "@/views/modules/share/ChangeCategory.js"
export default {
    name: 'FormLiteComponentList',
    mixins: [BaseList,ChangeCategory],
    components: {
        RxFit,
        RxCategoryTreeeditor
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index', '序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('componentName','组件名称'), dataIndex: 'name', width: 100},
                {title: this.i18n('componentAlias','组件别名'), dataIndex: 'alias', width: 100},
                {title: this.i18n('componentType','组件类型'), dataIndex: 'nodeType', width: 100, scopedSlots: {customRender: 'nodeType'}},
                {title: this.i18n('type','类型'), dataIndex: 'type', width: 100, scopedSlots: {customRender: 'type'}},
                {title: this.i18n('enabled','启用'), dataIndex: 'enabled', width: 60, scopedSlots: {customRender: 'enabled'}},
                {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 140},
                {title: this.$ti18('rxList.action', '操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component: FormLiteComponentEdit,
            comment: this.i18n('liteFlowComponent',"规则引擎组件"),
            widthHeight: ['800px', '600px'],
            fitSearch: false,
            statisticConfig: {
                type: "static_form",
                table: "FORM_LITE_COMPONENT t",
                field: "TREE_ID_",
            },
            statusMap: {
                "1": {color: 'green', text: this.$ti18('rxList.yes', '是')},
                "0": {color: 'red', text: this.$ti18('rxList.no', '否')},
            },
            nodeTypeMap: {
                "":"",
                "bpm-activity": this.i18n('activity','普通节点'),
                "bpm-select": this.i18n('select','选择节点'),
            },
            typeMap: {
                "":"",
                "script": this.i18n('script','脚本'),
                "bean": "Bean",
            },
            //变更分类配置
            categoryConfig:{
                Api:FormLiteComponentApi,
                catKey:"FORM",
                gridRef:"table"
            }
        }
    },
    created(){
        this.isUserManager(this.$route.query.appId);
        this.needFilterAppId("isAppMenu");
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "formLiteFlow", key);
        },
        delById(ids) {
            return FormLiteComponentApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormLiteComponentApi.query(parameter)
        },
        handSelect(curRow) {
            this.curTree = curRow
            var treeId = curRow.treeId;
            let params = {
                Q_TREE_ID__S_EQ: ""
            }
            if (treeId != "0") {
                params.Q_TREE_ID__S_EQ = treeId;
            } else {
                params.Q_TREE_ID__S_EQ = "";
            }
            this.loadData(params)
        },

    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

